package club.babyf.nativeai.common;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import java.util.HashMap;
import java.util.Map;

/**
 * BaseResponse.
 *
 * @author zhanglei.
 * @date 2025/2/21 15:44.
 * @description 基础响应格式.
 */
public class BaseResponse {

    /**
     * 成功响应
     *
     * @return ResponseEntity
     */
    public static ResponseEntity<Object> ok() {
        return ResponseEntity.ok(okBody());
    }

    /**
     * 带返回值的成功响应
     *
     * @param data 返回数据
     * @return ResponseEntity
     */
    public static ResponseEntity<Object> ok(Object data) {
        return ResponseEntity.ok(okBody(data));
    }

    /**
     * 带返回值Map的成功响应
     *
     * @param map 返回数据
     * @return ResponseEntity
     */
    public static ResponseEntity<Object> okMap(Map<String, Object> map) {
        return ResponseEntity.ok(okBody(map));
    }

    public static Map<String, Object> okBody() {
        Map<String, Object> hashMap = new HashMap<>(2);
        hashMap.put("code", HttpStatus.OK.value());
        hashMap.put("message", "success");
        hashMap.put("success", true);
        return hashMap;
    }

    public static Map<String, Object> okBody(Object data) {
        Map<String, Object> hashMap = okBody();
        hashMap.put("data", data);
        return hashMap;
    }

    public static Map<String, Object> okBody(Map<String, Object> map) {
        Map<String, Object> hashMap = okBody();
        hashMap.putAll(map);
        return hashMap;
    }

}
